package com.egg.auth.controller.feign;

import com.egg.auth.entity.role.Role;
import com.egg.auth.feign.AuthRoleFeignClient;
import com.egg.auth.service.role.IRoleService;
import com.egg.common.context.util.LocalThreadContextUtils;
import com.egg.common.core.model.controller.FeignController;
import com.egg.common.core.model.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Slf4j
@Api(tags = FeignController.API_PREFIX + "角色中心")
@RestController
@RequestMapping("/role")
public class FeignRoleController extends FeignController implements AuthRoleFeignClient {


    @Autowired
    private IRoleService roleService;


    @Override
    @ApiOperation(value = "用户是否为管理员")
    @GetMapping("/has-admin")
    public ResponseData<Boolean> hasAdminGet() {
        Long userId = LocalThreadContextUtils.getUserId();
        List<Role> roleList = roleService.findEnabledByUserId(userId);
        boolean hasAdmin = roleService.hasAdmin(roleList);
        return ResponseData.success(hasAdmin);
    }

}
